package singleton;

public class TestVolatile {
    boolean status = false;

    /**
     * 状态切换为true
     */
    public void changeStatus() {
        status = true;
    }

    /**
     * 若状态为true，则running。
     */
    public void run() {
        if (status) {
            System.out.println("running....");
        }
    }

    public static void main(String[] args) {
        TestVolatile testVolatile = new TestVolatile();
        new Thread(new Runnable() {
            @Override
            public void run() {
                testVolatile.changeStatus();
                testVolatile.run();
            }
        }).start();

        new Thread(new Runnable() {
            @Override
            public void run() {
                testVolatile.run();
            }
        }).start();

    }
}